package cn.entity.img;

import cn.entity.utils.Paint;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Background {
    private int x0;
    private int stop;
    private int end;
    private int index;

    private int width;
    private int height;
    private BufferedImage[] images;
    public Background() throws IOException {
        this.x0 = 0;
        this.stop = 650*2;
        this.end =650*4;
        images = new BufferedImage[5];
        for(int i = 0; i < images.length; i++) {
            images[i]= ImageIO.read(new File("img/bg/bg"+i+".png"));
        }
       width=800;
       height=600;

    }
public BufferedImage getImage(int index) {
        return images[index];
}
public int getHeight() {
        return height;
    }
public int step(int speed){
        if(x0+3200>=0){
          if(x0+800>0&& cn.entity.utils.Paint.a==3){
              x0-=speed;
              if(x0+800<=0){
                  return 1;
              }
          }
          else if(x0+800*2>0&& Paint.a==3){
              x0-=speed;
              if(x0+800*2<=0){
                  return 1;
              }
          }
        }
        return 0;
}
public void paint(Graphics g) {
    g.drawImage(getImage(0),getX0(),0,getWidth(),getHeight(),null);
    g.drawImage(getImage(2),getX0()+800*2,0,getWidth(),getHeight(),null);
    g.drawImage(getImage(3),getX0()+800*3,0,getWidth(),getHeight(),null);
    g.drawImage(getImage(4),getX0()+800*4,0,getWidth(),getHeight(),null);
    g.drawImage(getImage(1),getX0()+800,0,getWidth(),getHeight(),null);
}
public int getX0() {
        return x0;
}
public int getStop(){
        return stop;
}
public int getEnd() {
        return end;
}
    public int getWidth() {
        return width;
    }
}
